import axiosInstance from './axiosInstance';
import {
  CommentTag,
  Comment,
  CommentQueryParams,
  CommentPageResult,
  BatchPredictionParams,
  PredictionResult
} from '@/types/comment';
import { ApiResponse } from '@/types/api'; // 从共享类型文件导入

/**
 * 获取所有评论标签
 */
export const getCommentTags = async (): Promise<{ tags: CommentTag[] }> => {
  const response: ApiResponse<{ tags: CommentTag[] }> = await axiosInstance.get('/comments/tags');
  return response.data;
};

/**
 * 获取评论列表（分页）
 */
export const getComments = async (params: CommentQueryParams): Promise<CommentPageResult> => {
  const response: ApiResponse<CommentPageResult> = await axiosInstance.get('/comments', { params });
  return response.data;
};

/**
 * 获取单条评论详情
 */
export const getCommentById = async (id: string): Promise<Comment> => {
  const response: ApiResponse<Comment> = await axiosInstance.get(`/comments/${id}`);
  return response.data;
};

/**
 * 单条评论预测标签
 */
export const predictComment = async (
  comment: string,
  model: string
): Promise<PredictionResult> => {
  const response: ApiResponse<PredictionResult> = await axiosInstance.post('/comments/predict', {
    comment,
    model
  });
  return response.data;
};

/**
 * 批量预测评论标签
 */
export const batchPredictComments = async (
  params: BatchPredictionParams
): Promise<PredictionResult[]> => {
  const response: ApiResponse<PredictionResult[]> = await axiosInstance.post(
    '/comments/batch-predict',
    params
  );
  return response.data;
};

/**
 * 手动为评论添加标签
 */
export const addTagsToComment = async (
  id: string,
  tagIds: string[]
): Promise<Comment> => {
  const response: ApiResponse<Comment> = await axiosInstance.post(`/comments/${id}/tags`, {
    tagIds
  });
  return response.data;
};
    